const fs = require('fs');
module.exports = {
  // sleep函数
  sleep: (ms) => {
    return new Promise((resolve) => setTimeout(resolve, ms));
  },
  // promise化异步读取方法
  promisify: (nodefunction) => {
    return function (...args) {
      return new Promise((resolve, reject) => {
        nodefunction.call(this, ...args, (err, data) => {
          console.log(data);
          if (err) {
            console.log(2);
            reject(err);
          } else {
            console.log(data);
            resolve(data);
          }
        });
      });
    };
  },

  appendContentSync: (targetFile, file) => {
    let content = fs.readFileSync(file, "utf-8");
    fs.appendFileSync(targetFile, content);
  },
};
